home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / SUPERPD.PAK / PAGESET.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  4KB  |  145 lines

  1. // pageset.cpp : implementation of the CPadView class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "superpad.h"
  15. #include <malloc.h>
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char BASED_CODE THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CPageSetupDlg dialog
  24.  
  25. IMPLEMENT_DYNAMIC(CPageSetupDlg, CDialog)
  26.  
  27. CPageSetupDlg::CPageSetupDlg(CWnd* pParent /*=NULL*/)
  28.     : CDialog(CPageSetupDlg::IDD, pParent)
  29. {
  30.     //{{AFX_DATA_INIT(CPageSetupDlg)
  31.     m_iFooterTime = -1;
  32.     m_iHeaderTime = -1;
  33.     //}}AFX_DATA_INIT
  34. }
  35.  
  36. void CPageSetupDlg::DoDataExchange(CDataExchange* pDX)
  37. {
  38.     CDialog::DoDataExchange(pDX);
  39.     //{{AFX_DATA_MAP(CPageSetupDlg)
  40.     DDX_Text(pDX, IDC_FOOTER, m_strFooter);
  41.     DDX_Text(pDX, IDC_HEADER, m_strHeader);
  42.     DDX_Radio(pDX, IDC_FOOTER_FILE, m_iFooterTime);
  43.     DDX_Radio(pDX, IDC_HEADER_FILE, m_iHeaderTime);
  44.     //}}AFX_DATA_MAP
  45. }
  46.  
  47. BEGIN_MESSAGE_MAP(CPageSetupDlg, CDialog)
  48.     //{{AFX_MSG_MAP(CPageSetupDlg)
  49.     //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51.  
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CPageSetup member functions
  54.  
  55. static void Replace(CString& strModify, LPCTSTR pszWhat, LPCTSTR pszWith)
  56.     // replace pszWhat with pwzWith in string strModify
  57. {
  58.     int i;
  59.     if ((i = strModify.Find(pszWhat)) >= 0)
  60.     {
  61.         strModify = strModify.Left(i) + pszWith +
  62.             strModify.Mid(i+lstrlen(pszWhat));
  63.     }
  64. }
  65.  
  66. void CPageSetupDlg::FormatFilePage(CString& strFormat,
  67.     LPCTSTR pszFileName, UINT nPage)
  68. {
  69.     TCHAR sz[32];
  70.     wsprintf(sz, _T("%d"), nPage);
  71.     ::Replace(strFormat, _T("&p"), sz);
  72.     if (pszFileName == NULL)
  73.     {
  74.         pszFileName = sz;
  75.         sz[0] = 0;
  76.     }
  77.     ::Replace(strFormat, _T("&f"), pszFileName);
  78. }
  79.  
  80. void CPageSetupDlg::FormatHeader(CString& strHeader, CTime& time,
  81.     LPCTSTR pszFileName, UINT nPage)
  82. {
  83.     CString strFormat = m_strHeader;
  84.     FormatFilePage(strFormat, pszFileName, nPage);
  85. #ifdef _UNICODE
  86.     int nLen = strFormat.GetLength();
  87.     char *pszFormat = (char*)_alloca(nLen+1);
  88.     wcstombs(pszFormat, strFormat, nLen+1);
  89.     strHeader = time.Format(pszFormat);
  90. #else
  91.     strHeader = time.Format(strFormat);
  92. #endif
  93. }
  94.  
  95. void CPageSetupDlg::FormatFooter(CString& strFooter, CTime& time,
  96.     LPCTSTR pszFileName, UINT nPage)
  97. {
  98.     CString strFormat = m_strFooter;
  99.     FormatFilePage(strFormat, pszFileName, nPage);
  100. #ifdef _UNICODE
  101.     int nLen = strFormat.GetLength();
  102.     char *pszFormat = (char*)_alloca(nLen+1);
  103.     wcstombs(pszFormat, strFormat, nLen+1);
  104.     strFooter = time.Format(pszFormat);
  105. #else
  106.     strFooter = time.Format(strFormat);
  107. #endif
  108. }
  109.  
  110.  
  111. static TCHAR BASED_CODE szPageSetup[] = _T("PageSetup");
  112. static TCHAR BASED_CODE szHeader[] = _T("Header");
  113. static TCHAR BASED_CODE szFooter[] = _T("Footer");
  114. static TCHAR BASED_CODE szHeaderTime[] = _T("HeaderTime");
  115. static TCHAR BASED_CODE szFooterTime[] = _T("FooterTime");
  116.  
  117. void CPageSetupDlg::Initialize()
  118. {
  119.     m_strHeader = AfxGetApp()->GetProfileString(szPageSetup, szHeader,
  120.         _T("File: &f"));
  121.     m_strFooter = AfxGetApp()->GetProfileString(szPageSetup, szFooter,
  122.         _T("Page: &p"));
  123.     m_iHeaderTime = AfxGetApp()->GetProfileInt(szPageSetup, szHeaderTime, 0);
  124.     m_iFooterTime = AfxGetApp()->GetProfileInt(szPageSetup, szFooterTime, 0);
  125.     m_strHeaderOld = m_strHeader;
  126.     m_strFooterOld = m_strFooter;
  127.     m_iHeaderTimeOld = m_iHeaderTime;
  128.     m_iFooterTimeOld = m_iFooterTime;
  129. }
  130.  
  131. void CPageSetupDlg::Terminate()
  132. {
  133.     if (m_strHeader != m_strHeaderOld)
  134.         AfxGetApp()->WriteProfileString(szPageSetup, szHeader, m_strHeader);
  135.     if (m_strFooter != m_strFooterOld)
  136.         AfxGetApp()->WriteProfileString(szPageSetup, szFooter, m_strFooter);
  137.     if (m_iHeaderTime != m_iHeaderTimeOld)
  138.         AfxGetApp()->WriteProfileInt(szPageSetup, szHeaderTime, m_iHeaderTime);
  139.     if (m_iFooterTime != m_iFooterTimeOld)
  140.         AfxGetApp()->WriteProfileInt(szPageSetup, szFooterTime, m_iFooterTime);
  141. }
  142.  
  143. /////////////////////////////////////////////////////////////////////////////
  144. // CPageSetupDlg message handlers
  145.